<?php
//////////////////////////////////////////////////////
// GPAC Database is Copyright 2002 Colin Todd       //
// Written by Colin Todd - All rights reserved.     //
//                                                  //
// colintodd@myfastmail.com                         //
//////////////////////////////////////////////////////

$alphabet = @$_GET['alphabet'];
$listfilter = "";
$listfilter = @$_GET['listfilter'];
$WhereFilter = "";
$listfilter_htmlcode =	 "listfilter=$listfilter&amp;";

if ($alphabet==null or $alphabet == ""){
    $alphabet="all";
}
$alphabet_htmlcode = 'alphabet='.$alphabet.'';

$link = 'index.php?view=Indv_az_list&amp;'.$alphabet_htmlcode.'&amp;';

$FamilyId = @$_GET['FamilyId'];
$IndividualId = $_GET['IndividualId'];

$WhereFilter = $PACTS_cfg->getListHeader($listfilter_htmlcode,$alphabet,"index.php?view=Indv_az_list","index.php?view=Indv_allentries","Individuals",$listfilter,"IndividualId=$IndividualId&amp;FamilyId=$FamilyId");

if (strlen($IndividualId) > 0) {

    $sql = "SELECT *, ".$PACTS_cfg->individualtablename.".CommentText as IndvCommentText FROM ((($PACTS_cfg->individualtablename INNER JOIN $PACTS_cfg->familytablename ON $PACTS_cfg->individualtablename.FamilyId = $PACTS_cfg->familytablename.FamilyId) LEFT JOIN $PACTS_cfg->gendertablename ON $PACTS_cfg->individualtablename.GenderCode = $PACTS_cfg->gendertablename.GenderCode) LEFT  JOIN $PACTS_cfg->titletablename ON $PACTS_cfg->individualtablename.Title = $PACTS_cfg->titletablename.Title) LEFT  JOIN $PACTS_cfg->roletypetablename ON $PACTS_cfg->individualtablename.RoleTypeCode = $PACTS_cfg->roletypetablename.RoleTypeCode WHERE $PACTS_cfg->individualtablename.IndividualId=$IndividualId;";
    $result = mysql_query($sql ,$PACTS_cfg->dblink);
    $resultsnumber = mysql_num_rows($result);
    //	echo "&nbsp;<b>Number of entries: $resultsnumber</b><br />";
    $links = mysql_fetch_assoc($result);

    //echo "<pre>";
    //print_r($links);
    //echo "/<pre>";

    //   $IndividualId = //$links["Individual.IndividualId"];
    $FamilyId = $links['FamilyId'];
    $FirstName = $links["FirstName"];
    $Surname = $links["Surname"];
    //   $ResidentialAddress = $PACTS_cfg->getFormattedResidentialAddress($FamilyId,"<br />",TRUE,FALSE,FALSE);
    $ResidentialAddress = $PACTS_cfg->getFormattedResidentialAddress($FamilyId,"<br />",TRUE,FALSE,FALSE,FALSE,TRUE,"", TRUE, FALSE,TRUE,",",TRUE);

    if ($links["MailingAddressIndicator"]=='Y')
    {
        $PostalAddress = $ResidentialAddress;
    }else
    {
        $PostalAddress = $PACTS_cfg->getFormattedPostalAddress($FamilyId,"<br />",TRUE,FALSE,FALSE,TRUE,TRUE);
    }

    //   $address = $links["ResidentialStreetName"];
    $HomePhone = $PACTS_cfg->getFormattedHomePhoneNumber($FamilyId," ",FALSE, TRUE,TRUE);
    $HomeFax = $PACTS_cfg->getFormattedHomeFaxNumber($FamilyId," ",FALSE, TRUE,TRUE);
    $MobilePhone = $PACTS_cfg->getFormattedMobilePhoneNumber($links["IndividualId"]," ",FALSE,TRUE,TRUE);
    $WorkPhone = $PACTS_cfg->getFormattedWorkPhoneNumber($links["IndividualId"]," ",FALSE,TRUE,TRUE);
    $WorkFax = $PACTS_cfg->getFormattedWorkFaxNumber($links["IndividualId"]," ",FALSE,TRUE,TRUE);
    $HomeEmail = htmlspecialchars($PACTS_cfg->getEmailAddress($IndividualId,"HOME",TRUE));
    $WorkEmail = htmlspecialchars($PACTS_cfg->getEmailAddress($IndividualId,"WORK",TRUE));
    $Title = $PACTS_cfg->getLookValue($PACTS_cfg->titletablename, "Title", $links["Title"], "Description");
    $Gender = $PACTS_cfg->getLookValue( $PACTS_cfg->gendertablename,"GenderCode", $links["GenderCode"], "Description");
    $role = $links["RoleTypeCode"];
    $ShortName = $links["ShortName"];
    $DOB = $PACTS_cfg->myts_date("jS F Y",$links["BirthDate"],0,5,8,11);
    //   $DOB = $links["BirthDate"];
    $AgeRange = $links["AgeRange"];
    $Comment = htmlspecialchars(nl2br ($links["IndvCommentText"]));
    $ChurchDirectoryIndicator  = $links["ChurchDirectoryIndicator"];
    $BaptismContactIndicator = $links["BaptismContactIndicator"];
    $WorkTypeCode = trim($PACTS_cfg->getLookValue( $PACTS_cfg->worktypetablename, "WorkTypeCode", $links["WorkTypeCode"], "Description"));
    $SchoolYear= $PACTS_cfg->getSchoolYear($links["KindergartenCommenceYear"]);


    echo '<p />'."\n";
    echo '<div id="details-section">'."\n";
    echo '<div id="viewHeading">'."\n";
    echo $PACTS_cfg->getIndvNavBar($IndividualId, $FamilyId."&amp;".$listfilter_htmlcode.$alphabet_htmlcode, FALSE, TRUE, TRUE, "Fmly_view","",TRUE,"",FALSE);

    ////////////////////////////////

    echo '<p class="IndvName">'.trim("$Title $FirstName $Surname").':</p>'."\n";
    echo '<p class="IndvRole">'.$Gender.' '.$role.'</p>'."\n";
    echo '<hr class="left200px" />'."\n";
    //    echo '</ul>'."\n";
    echo '</div>'."\n";


    echo '<div id="viewDetailsC1">'."\n";
    echo '<ul>'."\n";
    echo '<li><p class="viewDetailsHeader">Title:</p><p class="viewDetailsData">'.$Title.'</p></li>'."\n";
    echo '<li><p class="viewDetailsHeader">First Name:</p><p class="viewDetailsData">'.$FirstName.'</p></li>'."\n";
    echo '<li><p class="viewDetailsHeader">Surname Name:</p><p class="viewDetailsData">'.$Surname.'</p></li>'."\n";
    if (strlen($ShortName)>0) {echo '<li><p class="viewDetailsHeader">ShortName:</p><p class="viewDetailsData">'.$ShortName.'</p></li>'."\n";}
    echo '</ul>'."\n";
    echo '<ul>'."\n";
    echo '<li><p class="viewDetailsHeader">DOB:</p><p class="viewDetailsData">'.$DOB.'</p></li>'."\n";
    echo '<li><p class="viewDetailsHeader">Age Range:</p><p class="viewDetailsData">'.$AgeRange.'</p></li>'."\n";
    if(strlen($WorkTypeCode)>0){echo '<li><p class="viewDetailsHeader">Work Type:</p><p class="viewDetailsData">'.$WorkTypeCode.'</p></li>'."\n";}
    if(strlen($SchoolYear)>0) {echo '<li><p class="viewDetailsHeader">School Year:</p><p class="viewDetailsData">'.$SchoolYear.'</p></li>'."\n";}
    echo '</ul>'."\n";
    echo '<ul>'."\n";
    echo '<li><p class="viewDetailsHeader">Home Phone:</p><p class="viewDetailsData">'.$HomePhone.'</p></li>'."\n";
    echo '<li><p class="viewDetailsHeader">Mobile Phone:</p><p class="viewDetailsData">'.$MobilePhone.'</p></li>'."\n";
    if(strlen($HomeFax)>0) {echo '<li><p class="viewDetailsHeader">Home Fax:</p><p class="viewDetailsData">'.$HomeFax.'</p></li>'."\n";}
    echo '</ul>'."\n";

    if(strlen($WorkPhone)>0 || strlen($WorkFax)>0){
        echo '<ul>'."\n";
        if(strlen($WorkPhone)>0) {echo '<li><p class="viewDetailsHeader">Work Phone:</p><p class="viewDetailsData">'.$WorkPhone.'</p></li>'."\n";}
        if(strlen($WorkFax)>0) {echo '<li><p class="viewDetailsHeader">Work Fax:</p><p class="viewDetailsData">'.$WorkFax.'</p></li>'."\n";}
        echo '</ul>'."\n";
    }
    echo '<ul>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Home Address:</p><p class="viewDetailsData">'.$ResidentialAddress.'</p></li>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Postal Address:</p><p class="viewDetailsData">'.$PostalAddress.'</p></li>'."\n";
    echo '</ul>'."\n";


    echo '<ul>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Home Email:</p><p class="viewDetailsData"><a title="Send email to '.$FirstName.' '.$Surname.' ('.$HomeEmail.')" href="mailto:'.$HomeEmail.'" >'.$HomeEmail.'</a></p></li>'."\n";
    if(strlen($WorkEmail)>0){    echo '<li class="colw50pc"><p class="viewDetailsHeader">Work Email:</p><p class="viewDetailsData"><a title="Send email to '.$FirstName.' '.$Surname.' ('.$WorkEmail.')" href="mailto:'.$WorkEmail.'" >'.$WorkEmail.'</a></p></li>'."\n";}
    echo '</ul>'."\n";


    echo '<ul>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Church Directory:</p><p class="viewDetailsData">'.$ChurchDirectoryIndicator.'</p></li>'."\n";
    echo '</ul>'."\n";
    echo '<ul>'."\n";
    echo '<li><p class="viewDetailsHeader">Baptism Contact:</p><p class="viewDetailsData">'.$BaptismContactIndicator.'</p></li>'."\n";

    echo '</ul>'."\n";


    echo '<ul>'."\n";
    echo '<li class="colw100pc"><p class="viewDetailsHeader">Comments:</p><p class="viewDetailsData">'.str_replace("\n", "<br />", $Comment).'</p></li>'."\n";

    echo '</ul>'."\n";
    if(strlen($links["IndividualPhoto"])>0) {

        echo '<ul>'."\n";
        echo '<li class="colw100pc"><p class="viewDetailsHeader">Photo:</p>'."\n";
        echo '<p class="viewDetailsData">'."\n";
        echo '<a href="index.php?view=display_image_full&amp;IndividualId='.$IndividualId.'" >'."\n";
        echo '<img src="index.php?view=display_image_thumb&amp;IndividualId='.$IndividualId.'&amp;width=150" alt="Open picture in new window" />'."\n";
        echo '</a>'."\n";

        echo '</p></li>'."\n";

        echo '</ul>'."\n";
    }
    echo '</div>'."\n";


    //    echo '<center><hr width=80%></center>'."\n";


    $sql = 'SELECT * FROM ((('.$PACTS_cfg->individualtablename.') LEFT JOIN '.$PACTS_cfg->gendertablename.' ON '.$PACTS_cfg->individualtablename.'.GenderCode = '.$PACTS_cfg->gendertablename.'.GenderCode) LEFT  JOIN '.$PACTS_cfg->titletablename.' ON '.$PACTS_cfg->individualtablename.'.Title = '.$PACTS_cfg->titletablename.'.Title) LEFT  JOIN '.$PACTS_cfg->roletypetablename.' ON '.$PACTS_cfg->individualtablename.'.RoleTypeCode = '.$PACTS_cfg->roletypetablename.'.RoleTypeCode WHERE '.$PACTS_cfg->individualtablename.'.FamilyId='.$FamilyId.' ORDER BY '.$PACTS_cfg->individualtablename.'.RoleTypeCode DESC, '.$PACTS_cfg->individualtablename.'.GenderCode DESC;';


    ///$sql = "SELECT * FROM $individual WHERE FamilyId=$FamilyId ORDER BY RoleTypeCode DESC, GenderCode DESC";
    //echo $sql."<p>";
    $result = mysql_query($sql,$PACTS_cfg->dblink);
    $FamilyName = $PACTS_cfg->getFormattedFamilyShortName($FamilyId," ");

    $sql_cnt = "SELECT Count(*) as Count FROM $PACTS_cfg->individualtablename WHERE FamilyId=$FamilyId";
    $result_cnt = mysql_query($sql_cnt,$PACTS_cfg->dblink);
    $row_cnt = mysql_fetch_assoc($result_cnt);
    echo '<table id="tFamilyOverview">'."\n";
    echo $PACTS_cfg->getFmlyNavBar( "", $FamilyId."&amp;".$listfilter_htmlcode.$alphabet_htmlcode, TRUE, TRUE, TRUE, "Fmly_allentries","",FALSE,FALSE,"$FamilyName Family:&nbsp;");

    echo "</tr></table>";


    echo '<table class="listType1">'."\n";

    $alternate = "2";
    while ($row = mysql_fetch_array($result)) {

        $IndividualId = $row["IndividualId"];
        $FamilyId = $row["FamilyId"];
        $firstname = $row["FirstName"];
        $lastname = $row["Surname"];
        $role= $row["RoleTypeCode"];
        $Gender = $PACTS_cfg->getLookValue($PACTS_cfg->gendertablename,"GenderCode  ", $row["GenderCode"], "Description");

        //echo "<tr><td>GEnder $Gender ".$links["GenderCode"]." </td></tr>";

        if ($alternate == "1") {
            $color = "#ffffff";
            $alternate = "2";
        }
        else {
            $color = "#ffffff";
            $alternate = "1";
        }
        echo $PACTS_cfg->getIndvNavBar($IndividualId."&amp;".$listfilter_htmlcode.$alphabet_htmlcode, $FamilyId, TRUE, TRUE, TRUE, "Fmly_view","alphabet=$alphabet"   ,TRUE,"$lastname, $firstname <i>(".trim("$Gender $role").")</i>");
        echo '</tr>'."\n";

        //echo"</tr>";
    }

    echo "</table>";
    echo '</div>'."\n";


    ///////////////////////////////








} else {

    echo "You need to select an ID number of a data entry";

}


?>